package me.xhy.java.springboot3.webflux.s01simplereactorhttpserver;

import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
import reactor.core.publisher.Mono;
import reactor.netty.http.server.HttpServer;

import java.util.concurrent.TimeUnit;

public class S01ReactorHttpServer {

  public static void main(String[] args) throws Exception {

    // 1. 一个能处理 Http 请求的处理器
    HttpHandler httpHandler = (request, response) -> {
      return Mono.empty();
    };

    // 2. 启动服务器
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
    // 3. 启动Netty服务器
    HttpServer.create().host("0.0.0.0").port(8080).handle(adapter).bindNow();
    // 4. 测试，使用阻塞方法阻止主线程退出
    TimeUnit.SECONDS.sleep(10);

  }
}
